package com.comba.nutz.boot.auth.server.service.impl;

import com.comba.nutz.boot.auth.server.entity.AccountEntity;
import com.comba.nutz.boot.auth.server.service.AccountService;
import com.comba.nutz.boot.starter.dao.CndPlus;
import com.comba.nutz.boot.starter.impl.BaseServiceImpl;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author george
 */
@Service
public class AccountServiceImpl extends BaseServiceImpl<AccountEntity> implements AccountService {

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        UserDetails userDetails = (UserDetails) fetch(CndPlus.where("user_no", userName));
        if (userDetails == null) {
            throw new UsernameNotFoundException("用户不存在");
        }

        return userDetails;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void updateAccount(AccountEntity accountEntity) {
        _update(accountEntity);

        int a = 1 / 0;
    }

}
